<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/xhtml;charset=utf-8" http-equiv="Content-Type"/>
<meta content="IE=9" http-equiv="X-UA-Compatible"/>
<meta content="Doxygen 1.8.13" name="generator"/>
<title>OpenCV: The module brings implementations of different image hashing algorithms.</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script src="../../jquery.js" type="text/javascript"></script>
<script src="../../dynsections.js" type="text/javascript"></script>
<script src="../../tutorial-utils.js" type="text/javascript"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script src="../../search/searchdata.js" type="text/javascript"></script>
<script src="../../search/search.js" type="text/javascript"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js" type="text/javascript"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellpadding="0" cellspacing="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
    <span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script src="../../menudata.js" type="text/javascript"></script>
<script src="../../menu.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow" onkeydown="return searchBox.OnSearchSelectKey(event)" onmouseout="return searchBox.OnSearchSelectHide()" onmouseover="return searchBox.OnSearchSelectShow()">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe frameborder="0" id="MSearchResults" name="MSearchResults" src="javascript:void(0)">
</iframe>
</div>
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> |
<a href="#enum-members">Enumerations</a> |
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">The module brings implementations of different image hashing algorithms.</div>  </div>
</div><!--header-->
<div class="contents">
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d25/classcv_1_1img__hash_1_1AverageHash.html">cv::img_hash::AverageHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Computes average hash value of the input image.  <a href="../../db/d25/classcv_1_1img__hash_1_1AverageHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d55/classcv_1_1img__hash_1_1BlockMeanHash.html">cv::img_hash::BlockMeanHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Image hash based on block mean.  <a href="../../df/d55/classcv_1_1img__hash_1_1BlockMeanHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d52/classcv_1_1img__hash_1_1ColorMomentHash.html">cv::img_hash::ColorMomentHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Image hash based on color moments.  <a href="../../df/d52/classcv_1_1img__hash_1_1ColorMomentHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/d29/classcv_1_1img__hash_1_1ImgHashBase.html">cv::img_hash::ImgHashBase</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">The base class for image hash algorithms.  <a href="../../de/d29/classcv_1_1img__hash_1_1ImgHashBase.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d00/classcv_1_1img__hash_1_1MarrHildrethHash.html">cv::img_hash::MarrHildrethHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Marr-Hildreth Operator Based Hash, slowest but more discriminative.  <a href="../../dd/d00/classcv_1_1img__hash_1_1MarrHildrethHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html">cv::img_hash::PHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">pHash  <a href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:"><td align="right" class="memItemLeft" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d5/d97/classcv_1_1img__hash_1_1RadialVarianceHash.html">cv::img_hash::RadialVarianceHash</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">Image hash based on Radon transform.  <a href="../../d5/d97/classcv_1_1img__hash_1_1RadialVarianceHash.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="enum-members"></a>
Enumerations</h2></td></tr>
<tr class="memitem:ga2f6c70af3b4924b4eea07cfa25ce0962"><td align="right" class="memItemLeft" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#ga2f6c70af3b4924b4eea07cfa25ce0962">cv::img_hash::BlockMeanHashMode</a> { <br/>
  <a class="el" href="../../d4/d93/group__img__hash.html#gga2f6c70af3b4924b4eea07cfa25ce0962a6f674fdb0f63d5d2f927cafbbf7f2707">cv::img_hash::BLOCK_MEAN_HASH_MODE_0</a> = 0, 
<br/>
  <a class="el" href="../../d4/d93/group__img__hash.html#gga2f6c70af3b4924b4eea07cfa25ce0962acd4cad53c6ffadcceffdf145c2039859">cv::img_hash::BLOCK_MEAN_HASH_MODE_1</a> = 1
<br/>
 }</td></tr>
<tr class="separator:ga2f6c70af3b4924b4eea07cfa25ce0962"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga482a3fdcb92bfff57cdc2aed2b5bc47e"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#ga482a3fdcb92bfff57cdc2aed2b5bc47e">cv::img_hash::averageHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr)</td></tr>
<tr class="memdesc:ga482a3fdcb92bfff57cdc2aed2b5bc47e"><td class="mdescLeft"> </td><td class="mdescRight">Calculates <a class="el" href="../../db/d25/classcv_1_1img__hash_1_1AverageHash.html" title="Computes average hash value of the input image. ">img_hash::AverageHash</a> in one call.  <a href="../../d4/d93/group__img__hash.html#ga482a3fdcb92bfff57cdc2aed2b5bc47e">More...</a><br/></td></tr>
<tr class="separator:ga482a3fdcb92bfff57cdc2aed2b5bc47e"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga33aaedc557653d1d541a78bbc119b116"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#ga33aaedc557653d1d541a78bbc119b116">cv::img_hash::blockMeanHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr, int mode=<a class="el" href="../../d4/d93/group__img__hash.html#gga2f6c70af3b4924b4eea07cfa25ce0962a6f674fdb0f63d5d2f927cafbbf7f2707">BLOCK_MEAN_HASH_MODE_0</a>)</td></tr>
<tr class="memdesc:ga33aaedc557653d1d541a78bbc119b116"><td class="mdescLeft"> </td><td class="mdescRight">Computes block mean hash of the input image.  <a href="../../d4/d93/group__img__hash.html#ga33aaedc557653d1d541a78bbc119b116">More...</a><br/></td></tr>
<tr class="separator:ga33aaedc557653d1d541a78bbc119b116"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gac2b55a4cec31a709cee9f9cdd6b933f7"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#gac2b55a4cec31a709cee9f9cdd6b933f7">cv::img_hash::colorMomentHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr)</td></tr>
<tr class="memdesc:gac2b55a4cec31a709cee9f9cdd6b933f7"><td class="mdescLeft"> </td><td class="mdescRight">Computes color moment hash of the input, the algorithm is come from the paper "Perceptual  Hashing  for  Color  Images
Using  Invariant Moments".  <a href="../../d4/d93/group__img__hash.html#gac2b55a4cec31a709cee9f9cdd6b933f7">More...</a><br/></td></tr>
<tr class="separator:gac2b55a4cec31a709cee9f9cdd6b933f7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gaf849522d808a8ef9ae2ed9422cf236b7"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#gaf849522d808a8ef9ae2ed9422cf236b7">cv::img_hash::marrHildrethHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr, float alpha=2.0f, float scale=1.0f)</td></tr>
<tr class="memdesc:gaf849522d808a8ef9ae2ed9422cf236b7"><td class="mdescLeft"> </td><td class="mdescRight">Computes average hash value of the input image.  <a href="../../d4/d93/group__img__hash.html#gaf849522d808a8ef9ae2ed9422cf236b7">More...</a><br/></td></tr>
<tr class="separator:gaf849522d808a8ef9ae2ed9422cf236b7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ga5eeee1e27bc45caffe3b529ab42568e3"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#ga5eeee1e27bc45caffe3b529ab42568e3">cv::img_hash::pHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr)</td></tr>
<tr class="memdesc:ga5eeee1e27bc45caffe3b529ab42568e3"><td class="mdescLeft"> </td><td class="mdescRight">Computes pHash value of the input image.  <a href="../../d4/d93/group__img__hash.html#ga5eeee1e27bc45caffe3b529ab42568e3">More...</a><br/></td></tr>
<tr class="separator:ga5eeee1e27bc45caffe3b529ab42568e3"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:gab0df0c3a059f1498a256c16a9d582970"><td align="right" class="memItemLeft" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d93/group__img__hash.html#gab0df0c3a059f1498a256c16a9d582970">cv::img_hash::radialVarianceHash</a> (<a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> inputArr, <a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> outputArr, double sigma=1, int numOfAngleLine=180)</td></tr>
<tr class="memdesc:gab0df0c3a059f1498a256c16a9d582970"><td class="mdescLeft"> </td><td class="mdescRight">Computes radial variance hash of the input image.  <a href="../../d4/d93/group__img__hash.html#gab0df0c3a059f1498a256c16a9d582970">More...</a><br/></td></tr>
<tr class="separator:gab0df0c3a059f1498a256c16a9d582970"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a id="details" name="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Provide algorithms to extract the hash of images and fast way to figure out most similar images in huge data set.</p>
<p>Namespace for all functions is <a class="el" href="../../de/d85/namespacecv_1_1img__hash.html">cv::img_hash</a>.</p>
<h3>Supported Algorithms</h3>
<ul>
<li>Average hash (also called Different hash)</li>
<li><a class="el" href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html" title="pHash ">PHash</a> (also called Perceptual hash)</li>
<li>Marr Hildreth Hash</li>
<li>Radial Variance Hash</li>
<li>Block Mean Hash (modes 0 and 1)</li>
<li>Color Moment Hash (this is the one and only hash algorithm resist to rotation attack(-90~90 degree))</li>
</ul>
<p>You can study more about image hashing from following paper and websites:</p>
<ul>
<li>"Implementation and benchmarking of perceptual image hash functions" <a class="el" href="../../d0/de3/citelist.html#CITEREF_zauner2010implementation">[289]</a></li>
<li>"Looks Like It" <a class="el" href="../../d0/de3/citelist.html#CITEREF_lookslikeit">[131]</a></li>
</ul>
<h3>Code Example</h3>
<div class="fragment"><div class="line"><span class="preprocessor">#include "<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="../../da/d74/ocl_8hpp.html">opencv2/core/ocl.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>"</span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="../../d4/d59/img__hash_8hpp.html">opencv2/img_hash.hpp</a>"</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../de/d85/namespacecv_1_1img__hash.html">cv::img_hash</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"></div><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><span class="keyword">inline</span> <span class="keywordtype">void</span> test_one(<span class="keyword">const</span> std::string &amp;title, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;a, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;b)</div><div class="line">{</div><div class="line">    cout &lt;&lt; <span class="stringliteral">"=== "</span> &lt;&lt; title &lt;&lt; <span class="stringliteral">" ==="</span> &lt;&lt; endl;</div><div class="line">    <a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html">TickMeter</a> tick;</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> hashA, hashB;</div><div class="line">    <a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;ImgHashBase&gt;</a> func;</div><div class="line">    func = T::create();</div><div class="line"></div><div class="line">    tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#ac9a8a593b4bd1c4ea6a1076c735260dd">reset</a>(); tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#a564bc8b0bebcfc6c96f85fc48643e273">start</a>();</div><div class="line">    func-&gt;compute(a, hashA);</div><div class="line">    tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#aa6dfbdc68373d10e371bd35f92c7adb3">stop</a>();</div><div class="line">    cout &lt;&lt; <span class="stringliteral">"compute1: "</span> &lt;&lt; tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#afb68ae3f1d181fec9d1cd5d80bd3bdce">getTimeMilli</a>() &lt;&lt; <span class="stringliteral">" ms"</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#ac9a8a593b4bd1c4ea6a1076c735260dd">reset</a>(); tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#a564bc8b0bebcfc6c96f85fc48643e273">start</a>();</div><div class="line">    func-&gt;compute(b, hashB);</div><div class="line">    tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#aa6dfbdc68373d10e371bd35f92c7adb3">stop</a>();</div><div class="line">    cout &lt;&lt; <span class="stringliteral">"compute2: "</span> &lt;&lt; tick.<a class="code" href="../../d9/d6f/classcv_1_1TickMeter.html#afb68ae3f1d181fec9d1cd5d80bd3bdce">getTimeMilli</a>() &lt;&lt; <span class="stringliteral">" ms"</span> &lt;&lt; endl;</div><div class="line"></div><div class="line">    cout &lt;&lt; <span class="stringliteral">"compare: "</span> &lt;&lt; func-&gt;compare(hashA, hashB) &lt;&lt; endl &lt;&lt; endl;;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span> (argc != 3)</div><div class="line">    {</div><div class="line">        cerr &lt;&lt; <span class="stringliteral">"must input the path of input image and target image. ex : hash_samples lena.jpg lena2.jpg"</span> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">return</span> -1;</div><div class="line">    }</div><div class="line">    <a class="code" href="../../dc/d83/group__core__opencl.html#gab747fa4efd88d3188f4ebcbc8a639c1e">ocl::setUseOpenCL</a>(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> input = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(argv[1]);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> target = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>(argv[2]);</div><div class="line"></div><div class="line">    test_one&lt;AverageHash&gt;(<span class="stringliteral">"AverageHash"</span>, input, target);</div><div class="line">    test_one&lt;PHash&gt;(<span class="stringliteral">"PHash"</span>, input, target);</div><div class="line">    test_one&lt;MarrHildrethHash&gt;(<span class="stringliteral">"MarrHildrethHash"</span>, input, target);</div><div class="line">    test_one&lt;RadialVarianceHash&gt;(<span class="stringliteral">"RadialVarianceHash"</span>, input, target);</div><div class="line">    test_one&lt;BlockMeanHash&gt;(<span class="stringliteral">"BlockMeanHash"</span>, input, target);</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><h3>Performance under different attacks</h3>
<div class="image">
<img alt="attack_performance.JPG" src="../../attack_performance.JPG"/>
<div class="caption">
Performance chart</div></div>
 <h3>Speed comparison with <a class="el" href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html" title="pHash ">PHash</a> library (100 images from ukbench)</h3>
<div class="image">
<img alt="hash_computation_chart.JPG" src="../../hash_computation_chart.JPG"/>
<div class="caption">
Hash Computation chart</div></div>
<div class="image">
<img alt="hash_comparison_chart.JPG" src="../../hash_comparison_chart.JPG"/>
<div class="caption">
Hash comparison chart</div></div>
<p> As you can see, hash computation speed of <a class="el" href="../../de/d85/namespacecv_1_1img__hash.html">img_hash</a> module outperform <a href="http://www.phash.org/">PHash library</a> a lot.</p>
<p>PS : I do not list out the comparison of Average hash, <a class="el" href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html" title="pHash ">PHash</a> and Color Moment hash, because I cannot find them in <a class="el" href="../../df/d4e/classcv_1_1img__hash_1_1PHash.html" title="pHash ">PHash</a>.</p>
<h3>Motivation</h3>
<p>Collects useful image hash algorithms into opencv, so we do not need to rewrite them by ourselves again and again or rely on another 3rd party library(ex : PHash library). BOVW or correlation matching are good and robust, but they are very slow compare with image hash, if you need to deal with large scale CBIR(content based image retrieval) problem, image hash is a more reasonable solution.</p>
<h3>More info</h3>
<p>You can learn more about <a class="el" href="../../de/d85/namespacecv_1_1img__hash.html">img_hash</a> modules from following links, these links show you how to find similar image from ukbench dataset, provide thorough benchmark of different attacks(contrast, blur, noise(gaussion,pepper and salt), jpeg compression, watermark, resize).</p>
<p><a href="http://qtandopencv.blogspot.my/2016/06/introduction-to-image-hash-module-of.html">Introduction to image hash module of opencv</a> <a href="http://qtandopencv.blogspot.my/2016/06/speed-up-image-hashing-of-opencvimghash.html">Speed up image hashing of opencv(img_hash) and introduce color moment hash</a></p>
<h3>Contributors</h3>
<p>Tham Ngap Wei, <a href="#" onclick="location.href='mai'+'lto:'+'tha'+'mn'+'gap'+'we'+'i@g'+'ma'+'il.'+'co'+'m'; return false;">thamn<span style="display: none;">.nosp@m.</span>gapw<span style="display: none;">.nosp@m.</span>ei@gm<span style="display: none;">.nosp@m.</span>ail.<span style="display: none;">.nosp@m.</span>com</a> </p>
<h2 class="groupheader">Enumeration Type Documentation</h2>
<a id="ga2f6c70af3b4924b4eea07cfa25ce0962"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2f6c70af3b4924b4eea07cfa25ce0962">◆ </a></span>BlockMeanHashMode</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="../../d4/d93/group__img__hash.html#ga2f6c70af3b4924b4eea07cfa25ce0962">cv::img_hash::BlockMeanHashMode</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d8/d87/block__mean__hash_8hpp.html">opencv2/img_hash/block_mean_hash.hpp</a>&gt;</code></p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="gga2f6c70af3b4924b4eea07cfa25ce0962a6f674fdb0f63d5d2f927cafbbf7f2707"></a>BLOCK_MEAN_HASH_MODE_0 <div class="python_language">Python: cv.img_hash.BLOCK_MEAN_HASH_MODE_0</div></td><td class="fielddoc"><p>use fewer block and generate 16*16/8 uchar hash value </p>
</td></tr>
<tr><td class="fieldname"><a id="gga2f6c70af3b4924b4eea07cfa25ce0962acd4cad53c6ffadcceffdf145c2039859"></a>BLOCK_MEAN_HASH_MODE_1 <div class="python_language">Python: cv.img_hash.BLOCK_MEAN_HASH_MODE_1</div></td><td class="fielddoc"><p>use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value </p>
</td></tr>
</table>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga482a3fdcb92bfff57cdc2aed2b5bc47e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga482a3fdcb92bfff57cdc2aed2b5bc47e">◆ </a></span>averageHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::averageHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.averageHash(</td><td class="paramname">inputArr[, outputArr]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d7/d22/average__hash_8hpp.html">opencv2/img_hash/average_hash.hpp</a>&gt;</code></p>
<p>Calculates <a class="el" href="../../db/d25/classcv_1_1img__hash_1_1AverageHash.html" title="Computes average hash value of the input image. ">img_hash::AverageHash</a> in one call. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>Hash value of input, it will contain 16 hex decimal number, return type is CV_8U </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga33aaedc557653d1d541a78bbc119b116"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga33aaedc557653d1d541a78bbc119b116">◆ </a></span>blockMeanHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::blockMeanHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>mode</em> = <code><a class="el" href="../../d4/d93/group__img__hash.html#gga2f6c70af3b4924b4eea07cfa25ce0962a6f674fdb0f63d5d2f927cafbbf7f2707">BLOCK_MEAN_HASH_MODE_0</a></code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.blockMeanHash(</td><td class="paramname">inputArr[, outputArr[, mode]]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d8/d87/block__mean__hash_8hpp.html">opencv2/img_hash/block_mean_hash.hpp</a>&gt;</code></p>
<p>Computes block mean hash of the input image. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>Hash value of input, it will contain 16 hex decimal number, return type is CV_8U </td></tr>
    <tr><td class="paramname">mode</td><td>the mode </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="gac2b55a4cec31a709cee9f9cdd6b933f7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac2b55a4cec31a709cee9f9cdd6b933f7">◆ </a></span>colorMomentHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::colorMomentHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.colorMomentHash(</td><td class="paramname">inputArr[, outputArr]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d1/d01/color__moment__hash_8hpp.html">opencv2/img_hash/color_moment_hash.hpp</a>&gt;</code></p>
<p>Computes color moment hash of the input, the algorithm is come from the paper "Perceptual  Hashing  for  Color  Images
Using  Invariant Moments". </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>42 hash values with type <a class="el" href="../../d1/d1b/group__core__hal__interface.html#ga30a562691cc5987bc88eb7bb7a8faf2b">CV_64F(double)</a> </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="gaf849522d808a8ef9ae2ed9422cf236b7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf849522d808a8ef9ae2ed9422cf236b7">◆ </a></span>marrHildrethHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::marrHildrethHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float </td>
          <td class="paramname"><em>alpha</em> = <code>2.0f</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float </td>
          <td class="paramname"><em>scale</em> = <code>1.0f</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.marrHildrethHash(</td><td class="paramname">inputArr[, outputArr[, alpha[, scale]]]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d3/d20/marr__hildreth__hash_8hpp.html">opencv2/img_hash/marr_hildreth_hash.hpp</a>&gt;</code></p>
<p>Computes average hash value of the input image. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3, CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>Hash value of input, it will contain 16 hex decimal number, return type is CV_8U </td></tr>
    <tr><td class="paramname">alpha</td><td>int scale factor for marr wavelet (default=2). </td></tr>
    <tr><td class="paramname">scale</td><td>int level of scale factor (default = 1) </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="ga5eeee1e27bc45caffe3b529ab42568e3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5eeee1e27bc45caffe3b529ab42568e3">◆ </a></span>pHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::pHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.pHash(</td><td class="paramname">inputArr[, outputArr]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d1/d9c/phash_8hpp.html">opencv2/img_hash/phash.hpp</a>&gt;</code></p>
<p>Computes pHash value of the input image. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3, CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>Hash value of input, it will contain 8 uchar value </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
<a id="gab0df0c3a059f1498a256c16a9d582970"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab0df0c3a059f1498a256c16a9d582970">◆ </a></span>radialVarianceHash()</h2>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cv::img_hash::radialVarianceHash </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#ga353a9de602fe76c709e12074a6f362ba">cv::InputArray</a> </td>
          <td class="paramname"><em>inputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="../../dc/d84/group__core__basic.html#gaad17fda1d0f0d1ee069aebb1df2913c0">cv::OutputArray</a> </td>
          <td class="paramname"><em>outputArr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">double </td>
          <td class="paramname"><em>sigma</em> = <code>1</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int </td>
          <td class="paramname"><em>numOfAngleLine</em> = <code>180</code> </td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table><table class="python_language"><tr><th colspan="999" style="text-align:left">Python:</th></tr><tr><td style="width: 20px;"></td><td>outputArr</td><td>=</td><td>cv.img_hash.radialVarianceHash(</td><td class="paramname">inputArr[, outputArr[, sigma[, numOfAngleLine]]]</td><td>)</td></tr></table>
</div><div class="memdoc">
<p><code>#include &lt;<a class="el" href="../../d2/d76/radial__variance__hash_8hpp.html">opencv2/img_hash/radial_variance_hash.hpp</a>&gt;</code></p>
<p>Computes radial variance hash of the input image. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">inputArr</td><td>input image want to compute hash value, type should be CV_8UC4, CV_8UC3, CV_8UC1. </td></tr>
    <tr><td class="paramname">outputArr</td><td>Hash value of input </td></tr>
    <tr><td class="paramname">sigma</td><td>Gaussian kernel standard deviation </td></tr>
    <tr><td class="paramname">numOfAngleLine</td><td>The number of angles to consider </td></tr>
  </table>
  </dd>
</dl>
</div>
</div>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:41 for OpenCV by  <a href="http://www.doxygen.org/index.html">
<img alt="doxygen" class="footer" src="../../doxygen.png"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
